package assists
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class MoveLog extends Sprite
	{
		private var text:TextField;
		private var strInfo:String;
		
		private var _Stage:Stage;
		
		public function MoveLog(stage:Stage)
		{
			_Stage = stage;
			
			init();
		}
		
		private function init():void
		{
			text = new TextField;
			text.mouseEnabled = false;
			text.autoSize = TextFieldAutoSize.LEFT;
			text.multiline = false;
			text.wordWrap = false;
			text.text = "";
			text.x = _Stage.stageWidth;
			text.y = 0;
			this.addChildAt(text,0);
			
			var showMask:Sprite = new Sprite;
			showMask.graphics.beginFill(0xFFFFFF,0);
			showMask.graphics.drawRect(0,0,_Stage.stageWidth,40);
			showMask.graphics.endFill();
			this.addChildAt(showMask,1);
			
			this.mask = showMask;
		}
		
		public function set textInfo(str:String):void
		{
			if(str != ""){
				TextFieldUtils.setHtmlText(text,str);
				text.width = text.textWidth + 10;
				
				addFrame();
			}else{
				removeFrame();
			}
		}
		
		private function removeFrame():void
		{
			if(this.hasEventListener(Event.ENTER_FRAME)){
				this.removeEventListener(Event.ENTER_FRAME,moveHandler);
			}
		}
		
		private function addFrame():void
		{
			this.addEventListener(Event.ENTER_FRAME,moveHandler);
		}
		
		protected function moveHandler(event:Event):void
		{
			if(text.x > - text.textWidth){
				text.x = text.x - 1;
			}else{
				text.x = _Stage.stageWidth;
			}
		}
	}
}